Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAL/Linux-SGX] Fix Trusted Files degenerating to Allowed Files on fork #1796

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

dimakuv
Copy link

@dimakuv dimakuv commented Mar 7, 2024

Description of the changes

Previously, Trusted Files feature had the following bug: after fork, the metadata of currently-opened-in-parent-process TFs (SHA256 hashes for each chunk of the file) was not available in the child SGX enclave. This effectively degenerated all currently-opened TFs into Allowed Files, and thus the child enclave lost integrity guarantees in these TFs. An attacker could substitute the TF contents on the storage with arbitrary code/data, and the child enclave would not notice this.

This bug was exposed only in the child process (child SGX enclave) and only in these scenarios:

  • fork without execve: the child continues reading from one of the file descriptors pointing to a trusted file opened before fork();
  • fork with execve: the child reads from an inherited file descriptor pointing to a trusted file.

This PR also adds a test to verify this bug is fixed.

How to test this PR?

LibOS test (based on a GDB script) is added.


This change is Reviewable

@dimakuv dimakuv marked this pull request as ready for review March 7, 2024 07:38
@dimakuv dimakuv force-pushed the dimakuv/fix-trusted-files-as-allowed branch from 4292ee6 to 0277a1b Compare March 7, 2024 07:59
kailun-qin
kailun-qin previously approved these changes Mar 7, 2024
Copy link
Contributor

@kailun-qin kailun-qin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 13 of 13 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, all discussions resolved, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel)

Previously, Trusted Files feature had the following bug: after fork, the
metadata of currently-opened-in-parent-process TFs (SHA256 hashes for
each chunk of the file) was not available in the child SGX enclave. This
effectively degenerated all currently-opened TFs into Allowed Files, and
thus the child enclave lost integrity guarantees in these TFs. An
attacker could substitute the TF contents on the storage with arbitrary
code/data, and the child enclave would not notice this.

This bug was exposed only in the child process (child SGX enclave) and
only in these scenarios:
- fork without execve: the child continues reading from one of the file
  descriptors pointing to a trusted file opened before `fork()`;
- fork with execve: the child reads from an inherited file descriptor
  pointing to a trusted file.

This commit also adds a test to verify this bug is fixed.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
@dimakuv dimakuv force-pushed the dimakuv/fix-trusted-files-as-allowed branch from 0277a1b to d82e885 Compare March 7, 2024 11:03
Copy link
Author

@dimakuv dimakuv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 11 of 13 files reviewed, all discussions resolved, not enough approvals from maintainers (2 more required), not enough approvals from different teams (1 more required, approved so far: Intel) (waiting on @kailun-qin)


pal/src/host/linux-sgx/pal_host.h line 56 at r3 (raw file):

            /* below fields are used only for trusted files */
            sgx_chunk_hash_t* chunk_hashes; /* array of hashes of file chunks */
            void* umem;                     /* valid only when chunk_hashes != NULL and size > 0 */

In a previous iteration, I forgot that umem can be legitimately NULL if the underlying Trusted File is empty (then it cannot be mmapped, since there are no contents to mmap).

My misunderstanding led to me checking assert(handle->file.umem) everywhere. And on our Python tests it failed, because Python has some trusted files like __init__.py which are empty. So I fixed my asserts to only check umem when necessary.

I expanded the comment to not forget about this in the future.

Copy link
Contributor

@kailun-qin kailun-qin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, all discussions resolved, not enough approvals from maintainers (1 more required), not enough approvals from different teams (1 more required, approved so far: Intel)

Copy link
Member

@mkow mkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 10 of 13 files at r1, 1 of 1 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@mkow mkow merged commit d82e885 into master Mar 7, 2024
18 checks passed
@mkow mkow deleted the dimakuv/fix-trusted-files-as-allowed branch March 7, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants